package com.psbc.springbootstudydemo1.mapper;

import com.psbc.springbootstudydemo1.domain.User;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Repository
public class UserMapper {
    private static Map<String, User> userMap = new HashMap<>();
    static {
        userMap.put("jack",new User(1,"jack","123"));
        userMap.put("dalei",new User(2,"dalei","123456"));
        userMap.put("tom",new User(3,"tom","123456789"));
    }
    public User login(String name,String pwd){
        User user = userMap.get(name);
        if (user == null){
            return null;
        }
        if (user.getPwd().equals(pwd)){
            return user;
        }
        return null;
    }
    public List<User> userList(){
        ArrayList<User> users = new ArrayList<>();
        users.addAll(userMap.values());
        return users;
    }
}
